package com.nuoniu.sibanyun.controller.erp;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.erp.ErpDespatchType;
import com.nuoniu.sibanyun.service.erp.IErpDespatchTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 发运方式 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2020-12-08
 */
@RestController
@RequestMapping("/erp/despatchType")
@Api(value = "发运方式管理", tags = "发运方式管理")
public class ErpDespatchTypeController extends BaseController {

    @Autowired
    private IErpDespatchTypeService despatchTypeService;

    @ApiOperation("获取列表")
    @GetMapping("pageList")
    public HttpResult pageList(Page page, ErpDespatchType despatchType) {
        return HttpResult.ok(despatchTypeService.pageList(page, despatchType));
    }

    @ApiOperation("保存")
    @PostMapping("save")
    public HttpResult save(@RequestBody ErpDespatchType despatchType) {
        if(StringUtils.isBlank(despatchType.getCode())) {
            throw new NuoNiuException("编码不能为空");
        }
        if(StringUtils.isBlank(despatchType.getName())) {
            throw new NuoNiuException("名称不能为空");
        }

        despatchTypeService.saveDespatchType(despatchType);
        return HttpResult.ok();
    }

    @ApiOperation("删除")
    @PostMapping("delete")
    public HttpResult delete(@RequestBody List<Long> ids) {
        despatchTypeService.removeByIds(ids);
        return HttpResult.ok();
    }

}
